
IF NOT EXISTS (select 'x' 
				from sys.tables st
				inner join sys.schemas ss on st.schema_id = ss.schema_id
				where ss.name = 'DBO'
				and st.name = 'HC_ENV')
BEGIN
PRINT 'CREATE TABLE DBO.HC_ENV'
CREATE TABLE DBO.HC_ENV (
	[ENV_CD] [nvarchar](20) NOT NULL Primary key,
    [ENV_NM] [nvarchar](100) NOT NULL,
	[USR_CRTN_ID] [varchar](50) NOT NULL CONSTRAINT DF_HC_ENV_USR_CRTN_ID DEFAULT (suser_sname()),
	[USR_CRTN_TS] [datetime] NOT NULL CONSTRAINT DF_HC_ENV_USR_CRTN_TS DEFAULT (getdate()),
	[USR_MDFN_ID] [varchar](50) NOT NULL CONSTRAINT DF_HC_ENV_USR_MDFN_ID DEFAULT (suser_sname()),
	[USR_MDFN_TS] [datetime] NOT NULL  	CONSTRAINT DF_HC_ENV_USR_MDFN_TS DEFAULT (getdate())
)
END

IF NOT EXISTS (select 'x' 
				from sys.tables st
				inner join sys.schemas ss on st.schema_id = ss.schema_id
				where ss.name = 'DBO'
				and st.name = 'HC_ITEM')
BEGIN
PRINT 'CREATE TABLE DBO.HC_ITEM'
CREATE TABLE DBO.HC_ITEM (
	[ITEM_ID] [int] IDENTITY(1,1) NOT NULL Primary key,
    [ITEM_NM] [nvarchar](100) NOT NULL CONSTRAINT AK_ITEM_NM UNIQUE(ITEM_NM),
	[USR_CRTN_ID] [varchar](50)  NULL,
	[USR_CRTN_TS] [datetime] NOT NULL CONSTRAINT DF_HC_ITEM_USR_CRTN_TS DEFAULT (getdate()),
	[USR_MDFN_ID] [varchar](50)  NULL,
	[USR_MDFN_TS] [datetime] NOT NULL  	CONSTRAINT DF_HC_ITEM_USR_MDFN_TS DEFAULT (getdate())
)

END

IF NOT EXISTS (select 'x' 
				from sys.tables st
				inner join sys.schemas ss on st.schema_id = ss.schema_id
				where ss.name = 'DBO'
				and st.name = 'HC_ITEM_DETAIL')
BEGIN
PRINT 'CREATE TABLE DBO.HC_ITEM_DETAIL'
CREATE TABLE [dbo].[HC_ITEM_DETAIL](
	[ITEM_DETAIL_ID] [int] IDENTITY(1,1) NOT NULL Primary key,
	[ITEM_ID] [int] NOT NULL CONSTRAINT [FK_HC_ITEM_DETAIL_ITEM_ID] FOREIGN KEY([ITEM_ID])
REFERENCES [dbo].[HC_ITEM] ([ITEM_ID]),
	[ITEM_ADDRESS] [nvarchar](500) NOT NULL,
	[ENV_CD] [nvarchar](20) NULL CONSTRAINT [FK_HC_ITEM_DETAIL_ENV_CD] FOREIGN KEY([ENV_CD])
REFERENCES [dbo].[HC_ENV] ([ENV_CD]),
	[USR_CRTN_ID] [varchar](50) NULL,
	[USR_CRTN_TS] [datetime] NOT NULL CONSTRAINT DF_HC_ITEM_DETAIL_USR_CRTN_TS DEFAULT (getdate()),
	[USR_MDFN_ID] [varchar](50) NULL,
	[USR_MDFN_TS] [datetime] NOT NULL CONSTRAINT DF_HC_ITEM_DETAIL_USR_MDFN_TS DEFAULT (getdate()),
 CONSTRAINT [AK_HC_ITEM_DETAIL] UNIQUE NONCLUSTERED 
(
	[ITEM_ID] ASC,
	[ENV_CD] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END


IF NOT EXISTS (select 'x' 
				from sys.tables st
				inner join sys.schemas ss on st.schema_id = ss.schema_id
				where ss.name = 'DBO'
				and st.name = 'HC_ITEM_REPORT')
BEGIN
PRINT 'CREATE TABLE DBO.HC_ITEM_REPORT'
CREATE TABLE DBO.HC_ITEM_REPORT (
	[HC_ITEM_REPORT_ID] [int] IDENTITY(1,1) NOT NULL,
    [ITEM_DETAIL_ID] INT NOT NULL CONSTRAINT [FK_HC_ITEM_REPORT_DETAIL_ID] FOREIGN KEY([ITEM_DETAIL_ID])
REFERENCES [dbo].[HC_ITEM_DETAIL] ([ITEM_DETAIL_ID]),
    [HC_ITEM_STATU] VARCHAR (10) NOT NULL,
    [REPORT_GUID] VARCHAR(100) NOT NULL,
    [HC_ITEM_REPORT_DESC] NVARCHAR (1000) NULL,
	[USR_CRTN_ID] [varchar](50)  NULL,
	[USR_CRTN_TS] [datetime] NOT NULL CONSTRAINT DF_HC_ITEM_REPORT_USR_CRTN_TS DEFAULT (getdate()),
)

END
